import 'package:fl_chart/fl_chart.dart';
import 'package:sleep/help_style.dart';
import 'package:sleep/model/chat/chat_model.dart';
import 'package:sleep/page/fatigue/comp/chart_detail.dart';
import 'package:flutter/material.dart';

class TitleChart extends StatelessWidget {
  final List<FlSpot>? spots;
  final String title;
  final ChatModel chatConfig;
  final Widget? icon;
  const TitleChart(
      {Key? key,
      this.spots,
      required this.chatConfig,
      required this.title,
      this.icon})
      : super(key: key);

  Widget button(Widget label, Widget icon, VoidCallback onPressed) {
    return GestureDetector(
      onTap: onPressed,
      child: Row(
        children: [label, icon],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: HelpStyle.decoration,
      padding: const EdgeInsets.fromLTRB(12.0, 20.0, 12.0, 20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text(
                title,
                style: HelpStyle.contextStyle,
              ),
              SizedBox(width: HelpStyle.cellMargin),
              if (icon != null) icon!,
            ],
          ),
          SizedBox(height: HelpStyle.margin),
          FaDetailChart(
              aspectRatio: 2,
              maxX: chatConfig.maxX,
              minX: chatConfig.minX,
              mimResolution: chatConfig.mimResolution,
              maxY: chatConfig.maxY,
              minY: chatConfig.minY,
              spots: spots),
        ],
      ),
    );
  }
}
